// src/common/appMixin.js
const appMixin = {
	methods: {
		gotoPage(url) {
			uni.navigateTo({
				url,
			});
		},
		// 获取今天的日期
		getToday() {
			let date = new Date();
			let year = date.getFullYear();
			let month = date.getMonth() + 1;
			let day = date.getDate();
			month = month < 10 ? "0" + month : month;
			day = day < 10 ? "0" + day : day;
			return year + "-" + month + "-" + day;
		},
		statusFun(status) {
			let value = "";
			let classs = "";
			switch (status) {
				case "0":
					value = "待审核";
					classs = "warning";
					break;
				case "1":
					value = "审核通过";
					classs = "success";
					break;
				case "2":
					value = "审核驳回";
					classs = "faile";
					break;
				case "3":
					value = "待提交";
					classs = "defult";
					break;
				default:
					value = "待审核";
					classs = "warning";
					break;
			}
			return {
				value,
				class: classs,
			};
		},
		// 递归提取所有字段的 title，生成 fieldTranslations 对象
		extractTitles(obj, translations = {}) {
			// 创建一个新的对象，用于存储提取的结果
			const result = {};

			// 遍历对象的所有字段
			for (const key in obj) {
				// 如果当前字段有 title 属性，保留该 title 属性
				if (obj[key].title) {
					result[key] = {
						title: obj[key].title
					};
				}

				// 如果当前字段有 option，并且 option 是对象或数组，递归处理
				if (obj[key].option && typeof obj[key].option === 'object') {
					result[key].option = this.extractTitles(obj[key].option);
				}
			}

			// 返回包含 title 字段的结构
			return result;
		},
	},
};

export default appMixin;